using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace S_Wings
{

  public class Game1 : Microsoft.Xna.Framework.Game
  {
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;
    // TODO: Discuss what the resolution should be, and if it should be resizeable.
    int current_screen;
    int current_level;
    int status, prev_status;
    Screen[] screens = null;

    public Game1()
    {
      graphics = new GraphicsDeviceManager(this);
      Content.RootDirectory = "Content";
      IsFixedTimeStep = false;  // TODO: Discuss if this should actually be fixed
      graphics.PreferredBackBufferWidth = Globl.SCREEN_WIDTH;
      graphics.PreferredBackBufferHeight = Globl.SCREEN_HEIGHT;
      graphics.ApplyChanges();
    }

    /// <summary>
    /// Allows the game to perform any initialization it needs to before starting to run.
    /// This is where it can query for any required services and load any non-graphic
    /// related content.  Calling base.Initialize will enumerate through any components
    /// and initialize them as well.
    /// </summary>
    protected override void Initialize() { base.Initialize(); }

    /// <summary>
    /// LoadContent will be called once per game and is the place to load
    /// all of your content.
    /// </summary>
    protected override void LoadContent()
    {
      spriteBatch = new SpriteBatch(GraphicsDevice);
      screens = new Screen[8];
      current_screen = (int)SCREEN.INTRO;
      current_level = 0;
      // Only load stuff for intro screen and main screen
    }

    /// <summary>
    /// UnloadContent will be called once per game and is the place to unload
    /// all content.
    /// </summary>
    protected override void UnloadContent() {}

    /// <summary>
    /// Allows the game to run logic such as updating the world,
    /// checking for collisions, gathering input, and playing audio.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Update(GameTime gameTime)
    {
      KeyboardState ks = Keyboard.GetState();
      GamePadState gs = GamePad.GetState(PlayerIndex.One);
      // Will eventually exit only if on title screen
      if (ks.IsKeyDown(Keys.Escape))
        this.Exit();
      double elapsedTime = gameTime.ElapsedGameTime.TotalSeconds;
      // Do update stuff
      /*
      status = screens[current_screen].update(elapsedTime, ks, gs);
      if(status != prev_status) {
        switch to new screen, call screen.load
        current_screen = new screen;
      }
      prev_status = status;
      //*/
      base.Update(gameTime);
    }

    /// <summary>
    /// This is called when the game should draw itself.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Draw(GameTime gameTime)
    {
      GraphicsDevice.Clear(Color.Black);
      base.Draw(gameTime);
    }
  }
}
